package org.spring.sample.eureka.client.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class IndexService {

	@Autowired
	private RestTemplate restTemplate;
	
	/**
	 * 配置熔断，使用hystrix断路器
	 */
	@HystrixCommand(fallbackMethod = "error")
	public String index(String str) {
		log.info("采用ribbon远程调用");
		return restTemplate.getForObject("http://service-index/index?name=" + str, String.class);
	}

	public String error(String name) {
		return "i`am sorry" + name + "is error";
	}
}
